package io.renren.modules.sys.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;


import io.renren.modules.sys.entity.SysProjectEntity;
import io.renren.modules.sys.service.SysProjectService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys/project")
public class SysProjectController  {
    @Autowired
    private SysProjectService sysProjectService;


    /**
     * 项目信息查询
     */
    @SysLog("查询项目")
    @RequestMapping("/info/{projectId}")
//    @RequiresPermissions("sys:project:info")
    public R info(@PathVariable("projectId") Long projectId){
        SysProjectEntity project = sysProjectService.queryObject(projectId);
        System.out.println("CONTRO查询方法"+project);

        return R.ok().put("project", project);

    }


    @SysLog("查询项目列表")
    @RequestMapping("/list")
//    @RequiresPermissions("sys:project:info")
    public R list(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        List<SysProjectEntity> list = sysProjectService.queryList(query);
        int total = sysProjectService.queryTotal();
        PageUtils pageUtil = new
                PageUtils(list, total, query.getLimit(), query.getPage());
        for(SysProjectEntity s :list){
            System.out.println(s.getProjectName());
        }
        return R.ok().put("page", pageUtil);

    }

    /**
     *保存新增项目
     */
    @SysLog("保存项目")
    @RequestMapping("/save")
//    @RequiresPermissions("sys:project:save")
    public R save(@RequestBody SysProjectEntity project){
        //验证页面数据
        ValidatorUtils.validateEntity(project);

        sysProjectService.save(project);
        System.out.println("CONTRO保存方法");
        return R.ok();
    }

    /**
     * 修改项目
     */
    @SysLog("修改项目")
    @RequestMapping("/update")
//    @RequiresPermissions("sys:project:update")
    public R update(@RequestBody SysProjectEntity project){
        ValidatorUtils.validateEntity(project);

        sysProjectService.update(project);
        System.out.println("CONTRO修改方法");
        return R.ok();
    }

    /**
     * 删除项目
     */
    @SysLog("删除项目")
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:project:delete")
    public R delete(@RequestBody Long projectId){
        sysProjectService.delete(projectId);
        System.out.println("CONTRO删除方法");
        return R.ok();
    }

}
